#!/bin/bash

inform()
{
	echo ""
	echo "submodule vender is not existed!"
	echo "you can execute the given command to init and update it."
	echo " \$ git submodule init"
	echo " \$ git submodule update"
	echo ""
	exit 1
}

export WORK_ROOT=`pwd`

SOURCE_ROOT="`dirname \"$0\"`"
SOURCE_ROOT="`( cd \"$SOURCE_ROOT\" && pwd )`"

if [ -f "${SOURCE_ROOT}/vender/build" ]; then 
	if [ -z $USE_VENDER_DIST ]; then
		cd "${SOURCE_ROOT}/vender"
		sh build "$@"
		if [ $? != 0 ]; then
			exit 1
		fi
	fi
else
	inform
fi

cd "${SOURCE_ROOT}/fibjs"
sh build "$@"
if [ $? != 0 ]; then
	exit 1
fi

cd "${SOURCE_ROOT}/fibjs/program"
sh build "$@"
if [ $? != 0 ]; then
	exit 1
fi

cd "${SOURCE_ROOT}/fibjs/installer"
sh build "$@"
if [ $? != 0 ]; then
	exit 1
fi

txtbld=$(tput bold)
bldred=${txtbld}$(tput setaf 1)
txtrst=$(tput sgr0)

printf "\n\n"
printf "\t${bldred} _______ _________ ______  _________ _______ ${txtrst}\n"
printf "\t${bldred}(  ____ \\\\\\__   __/(  ___ \\ \\__    _/(  ____ \\\\${txtrst}\n"
printf "\t${bldred}| (    \\/   ) (   | (   ) )   )  (  | (    \\/${txtrst}\n"
printf "\t${bldred}| (__       | |   | (__/ /    |  |  | (_____ ${txtrst}\n"
printf "\t${bldred}|  __)      | |   |  __ (     |  |  (_____  )${txtrst}\n"
printf "\t${bldred}| (         | |   | (  \\ \\    |  |        ) |${txtrst}\n"
printf "\t${bldred}| (_     ___) (___| (___) )/\\_)  )  /\\____) |${txtrst}\n"
printf "\t${bldred}(__/     \\_______/(______/ \\____/   \\_______)${txtrst}\n"
printf ""

printf "\\n\\tFIBJS has been successfully built.\\n\\n"

printf "\\tFor more information:\\n\\n"
printf "\\twebsite: http://fibjs.org\\n"
printf "\\trepository: https://github.com/fibjs\\n"
printf "\n\n"